from flask import Flask, jsonify, request, render_template
from zfnew import *
from flask_cors import CORS

app = Flask(__name__)
CORS(app)
app.config['JSON_AS_ASCII'] = False


@app.route('/info')
def get_info():
    # 查询个人信息
    # info = person.get_pinfo()
    #　return jsonify(info)
    return render_template('adddemo1.html')


@app.route('/grade', methods=["POST", "GET"])
def get_grade():
    username = request.form.get('username')
    password = request.form.get('password')


    base_url = 'https://jwxt.xcc.edu.cn/'
    lgn = Login(base_url=base_url)
    lgn.login(username, password)
    cookies = lgn.cookies  # cookiejar类cookies获取方法
    person = GetInfo(base_url=base_url, cookies=cookies)
    grade = person.get_grade('2019', '2')  # 2019年、第1学期(0 or 1 or 2 此处0为全年)
    return jsonify(grade)


@app.route('/schedule', methods=["POST", "GET"])
def get_schedule():
    # 查询课表信息
    username = request.form.get('username')
    password = request.form.get('password')



    base_url = 'https://jwxt.xcc.edu.cn/'
    lgn = Login(base_url=base_url)
    lgn.login(username, password)
    cookies = lgn.cookies  # cookiejar类cookies获取方法
    person = GetInfo(base_url=base_url, cookies=cookies)
    schedule = person.get_schedule('2020', '1')  # 2019年、第1学期(1 or 2)
    return jsonify(schedule)


if __name__ == '__main__':
    app.run()
